home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / terminal.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-14  |  8.1 KB  |  244 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- //
  5. // C++ Header File Name: terminal.h 
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer    
  8. // File Creation Date: 03/21/1997 
  9. // Date Last Modified: 03/15/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ---------- Include File Description and Details  ---------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. This is a terminal interface designed to be portable between
  32. DOS and UNIX systems. On UNIX systems the "curses" library is
  33. used to create terminal independent code. On MSDOS/Windows95
  34. systems the ANSI.SYS driver is used to simulate the basic
  35. functions of the "curses" library.
  36. */
  37. // ----------------------------------------------------------- //   
  38. #ifndef __TERMINAL_HPP
  39. #define __TERMINAL_HPP
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43.  
  44. // This include file is no longer used
  45. // #include "os_type.h" 
  46.  
  47. // Set this macro DOS and Windows applications
  48. // #ifndef __DOS__
  49. // #define __DOS__
  50. // #endif 
  51.  
  52. // Set this macro Generic Unix applications
  53. // #ifndef __UNIX__
  54. // #define __UNIX__
  55. // #endif 
  56.  
  57. #ifdef __UNIX__
  58. // NOTE: Redhat Linux 5.2 requires ncurses-devel-4.2-10.i386.rpm
  59. #include <curses.h> // Terminal independent I/O library
  60. #endif
  61.  
  62. #ifdef __DOS__
  63. #include <conio.h> // Console I/O library
  64. #endif
  65.  
  66. // Key definitions
  67. const int Escape = 27;
  68. #define CONTROL(c) ((c) & 037) 
  69.  
  70. // Screen (C)oordinates class
  71. class Coords
  72. {
  73. public:
  74.   Coords() { xpos = ypos = 0; }
  75.   Coords(int x, int y) { xpos = x; ypos = y; }
  76.   ~Coords() { }
  77.   Coords(const Coords &ob) { xpos = ob.xpos ; ypos = ob.ypos; }
  78.   Coords &operator=(const Coords &ob) {
  79.     xpos = ob.xpos ; ypos = ob.ypos; return *this;
  80.   } 
  81.   
  82. public:
  83.   int XPos() { return xpos; } // Current x coordinate
  84.   int YPos() { return ypos; } // Current y coordinate 
  85.   int XNext() { int x = xpos + 1; return x; } 
  86.   int YNext() { int y = ypos + 1; return y; }
  87.   int XPrev() { int x = xpos - 1; return x; }
  88.   int YPrev() { int y = ypos - 1; return y; }
  89.   int XOffset(int x) { xpos = xpos + x; return xpos; } 
  90.   int YOffset(int y) { ypos = ypos + y; return ypos; }
  91.   void SetXY(int x, int y) { xpos = x; ypos = y; }
  92.   void SetX(int x) { xpos = x; }
  93.   void SetY(int y) { ypos = y; }
  94.  
  95. private:
  96.   int xpos;
  97.   int ypos;
  98. };
  99.  
  100. // ANSI (T)erminal class
  101. class Terminal
  102. {
  103. public:
  104.   Terminal() { putback = 0; }
  105.   ~Terminal() { }
  106.  
  107. public: // Standard dialogs
  108.   int YesNo(int x = -1, int y = -1);
  109.   int YesNo(const char *s, int x = -1, int y = -1);
  110.   int GetYesNo();
  111.   void AnyKey(int x = -1, int y = -1);
  112.   void AnyKey(const char *s, int x = -1, int y = -1);
  113.   
  114. public: // Terminal setup and screen operations
  115.   void init();
  116.   void finish();
  117.   char *GetTerm() { return getenv("TERM"); }
  118.   int MaxLines() { return maxlines; } 
  119.   int MaxLines() const { return maxlines; }
  120.   int MaxCols() { return maxcols; }
  121.   int MaxCols() const { return maxcols; }
  122.   void SetMaxLines(int lines);
  123.   void SetMaxCols(int cols);
  124.   void MoveCursor(int x, int y) const;
  125.   void MoveCursor(int x, int y);
  126.   void ClearScreen() const;
  127.   void ClearScreen();
  128.   void ClearLine(int x = -1, int y = -1) const;
  129.   void ClearLine(int x = -1, int y = -1);
  130.   int Center(const char *s) const; // Return center coordinate for a string
  131.   int Center(char *s);
  132.   int Right(const char *s) const;  // Return right justifed coordinate
  133.   int Right(char *s);  
  134.   int ScreenCenter(const int offset) const; // Return screen's center
  135.   int ScreenCenter(int offset); 
  136.   
  137. public: // Output functions
  138.   void Write(const char c, int x = -1, int y = -1) const;
  139.   void Write(char c, int x = -1, int y = -1);
  140.   void Write(const unsigned char c, int x = -1, int y = -1) const;
  141.   void Write(unsigned char c, int x = -1, int y = -1);
  142.   void Write(const char *s, int x = -1, int y = -1) const;
  143.   void Write(char *s, int x = -1, int y = -1);
  144.   void Write(const long val, int x = -1, int y = -1) const;
  145.   void Write(long val, int x = -1, int y = -1);
  146.   void Write(const int val, int x = -1, int y = -1) const;
  147.   void Write(int val, int x = -1, int y = -1);
  148.   void Write(double val, int x = -1, int y = -1); 
  149.   void Write(const double val, int x = -1, int y = -1) const; 
  150.   void Write(float val, int x = -1, int y = -1); 
  151.   void Write(const float val, int x = -1, int y = -1) const; 
  152.   void StatusLine(const char *s) const;
  153.   void StatusLine(char *s);
  154.  
  155.   // The standout mode does not work the same on every terminal type.
  156.   // In order to maintain porablity avoid using these functions in
  157.   // code that needs to maintain a universal appearence when executed
  158.   // across multiple platforms.
  159.   void StandOut(const char *s, int x = -1, int y = -1) const;
  160.   void StandOut(char *s, int x = -1, int y = -1);
  161.   
  162. public: // Input functions
  163.   int KBWait() const;
  164.   unsigned char GetChar();
  165.   void GetString(char *string, int x = -1, int y = -1);
  166.   void GetPassword(char *string, int x = -1, int y = -1);
  167.   void PutBack(char c);
  168.   int GetInt(int x = -1, int y = -1);
  169.   long GetLong(int x = -1, int y = -1);
  170.   double GetFloat(int x = -1, int y = -1);
  171.  
  172. private:
  173.   char putback;
  174.   int maxlines;
  175.   int maxcols;
  176. };
  177.  
  178. extern Terminal I_TERM;    // Independent Teminal type object
  179. extern Terminal *terminal; // Global terminal pointer
  180.  
  181. #ifdef __DOS__
  182. // ===============================================================
  183. // Stand alone functions used to port this code from UNIX to DOS,
  184. // Windows 3.11, and Windows 95. These functions are used to
  185. // simulate the basic functionality of the vast CURSES library.
  186. // All of these functions rely on the ANSI.SYS driver installed
  187. // in the "config.sys" file: DEVICEHIGH=C:\WINDOWS\COMMAND\ANSI.SYS
  188. // in Windows 95 or DEVICEHIGH=C:\DOS\ANSI.SYS in DOS/Windows 3.11.
  189. // ===============================================================
  190. // chtype is the type used to store a character together with attributes.
  191. // It can be set to "char" to save space, or "long" to get more attributes.
  192. #ifdef    CHTYPE
  193. typedef    CHTYPE chtype;
  194. #else
  195. typedef unsigned long chtype;
  196. #endif // CHTYPE 
  197.  
  198. extern int LINES, COLS;
  199.  
  200. // TRUE and FALSE get defined so many times, let's not get in the 
  201. // way of other definitions.
  202. #ifndef TRUE
  203. #define    TRUE    1
  204. #endif
  205. #ifndef FALSE
  206. #define    FALSE    0
  207. #endif
  208. #ifndef ERR
  209. #define    ERR    -1
  210. #endif
  211. #ifndef OK 
  212. #define    OK    0
  213. #endif
  214.  
  215. int addch(const chtype c);
  216. int addstr(const char *s);
  217. int beep();
  218. int clear();
  219. int endwin();
  220. int move(int y, int x);
  221. int refresh();
  222. int standend();
  223. int standout();
  224.  
  225. // ===============================================================
  226. // The folling code is used for PC enhancements, used to emulate
  227. // the effect of the video attribute functions in the curses library.
  228. // All of the escape codes are compatible with vt100 terminals.
  229. void UnderlineText();
  230. void BoldText();
  231. void ReverseVideo();
  232. void NormalText();
  233. // ===============================================================
  234. #endif // __DOS__
  235.  
  236. #endif  // __TERMINAL_HPP 
  237. // ----------------------------------------------------------- // 
  238. // ------------------------------- //
  239. // --------- End of File --------- //
  240. // ------------------------------- //
  241.  
  242.  
  243.  
  244.